# == Class: autofslocal
#
# Full description of class autofslocal here.
#
# === Parameters
#
# Document parameters here.
#
# [*sample_parameter*]
#   Explanation of what this parameter affects and what it defaults to.
#   e.g. "Specify one or more upstream ntp servers as an array."
#
# === Variables
#
# Here you should define a list of variables that this module would require.
#
# [*sample_variable*]
#   Explanation of how this variable affects the funtion of this class and if
#   it has a default. e.g. "The parameter enc_ntp_servers must be set by the
#   External Node Classifier as a comma separated list of hostnames." (Note,
#   global variables should be avoided in favor of class parameters as
#   of Puppet 2.6.)
#
# === Examples
#
#  class { autofslocal:
#    servers => [ 'pool.ntp.org', 'ntp.local.company.com' ],
#  }
#
# === Authors
#
# Author Name <author@domain.com>
#
# === Copyright
#
# Copyright 2013 Your name here, unless otherwise noted.
#
class autofslocal::params{
  $enable_cvmfs     = false
  $enable_autolocal = true
  $enable_mucurafs  = false
  $autofs_extra     = []
  $autofs_eos       = false
  }
class autofslocal (
    $enable_cvmfs      = $autofslocal::params::enable_cvmfs,
    $enable_autolocal  = $autofslocal::params::enable_cvmfs,
    $enable_mucurafs   = $autofslocal::params::enable_cvmfs,
    $autofs_extra      = $autofslocal::params::autofs_extra,
    $autofs_eos        = $autofslocal::params::autofs_eos,
  ) inherits autofslocal::params {

  #package { 'autofs':
  #  ensure   => present,
  #  require  => Yumrepo['site']
  #}->
  case $operatingsystemmajrelease {
  '6': {
  package { 'autofs':
    ensure   => present,
    require  => Yumrepo['site']
  }->
    if $enable_cvmfs == "true" {
      if $autofs_eos {
        file { '/etc/auto.master':
          ensure   =>  file,
          owner    => 0,
          group    => 0,
          mode     => '0644',
          source   =>  "puppet:///modules/autofslocal/auto-cvmfs-eos.master",
          before   => Service['autofs'],
        }
      }
      else {
        file { '/etc/auto.master':
          ensure   =>  file,
          owner    => 0,
          group    => 0,
          mode     => '0644',
          source   =>  "puppet:///modules/autofslocal/auto-cvmfs.master",
          before   => Service['autofs'],
        }
      }
    }
    else {
      file { '/etc/auto.master':
        ensure   =>  file,
        owner    => 0,
        group    => 0,
        mode     => '0644',
        source   =>  "puppet:///modules/autofslocal/auto.master",
        before   => Service['autofs'],
      }
    }
  service {'autofs':
    ensure     =>  'running',
    enable     =>  true,
    name       =>  "autofs",
    hasstatus  =>  true,
    hasrestart =>  true,
    require     => Package['autofs'],
  }
  }
  '7','8','9': {
      file { '/etc/auto.master.d/local.autofs':
        ensure   =>  file,
        owner    => 0,
        group    => 0,
        mode     => '0644',
        content  => "/ihepbatch      file:/etc/auto.local    --timeout=60",
      }
      autofs::mount { 'ihep':
        master  => '/etc/auto_master',
        mount   => '/-',
        mapfile => '/etc/auto.ihep',
        options => '--timeout=120',
        use_dir => true,
      }
      autofs::mapfile { 'ihep':
        path     => '/etc/auto.ihep',
        mappings => [
          { 'key' => '/home/lhaaso', 'options' => 'fstype=nfs,soft,soft,intr,retrans=20,timeo=15,nfsvers=3,nosuid', 'fs' => 'lhuser.ihep.ac.cn:/lhaasohome' },
        ]
      }
    }
  }


  case $operatingsystemmajrelease {
    '5': {
      file { '/etc/auto.local':
        ensure   =>  file,
        owner    => 0,
        group    => 0,
        mode     => '0644',
        content  => template("autofslocal/auto.local.erb"),
        before   => Service['autofs'],
      }
    }
    '6','7': {
      file { '/etc/auto.local':
        ensure   =>  file,
        owner    => 0,
        group    => 0,
        mode     => '0644',
        content  => template("autofslocal/auto6.local.erb"),
        before   => Service['autofs'],
      }
    }
  }
  #service {'autofs':
  #  ensure     =>  'running',
  #  enable     =>  true,
  #  name       =>  "autofs",
  #  hasstatus  =>  true,
  #  hasrestart =>  true,
  #  require     => Package['autofs'],
  #}
  if $operatingsystemmajrelease >= '6' {
      package {'nfs-utils':
        ensure   => present,
        require  => Package['autofs']
      }
      service { 'rpcbind':
        ensure     => 'running',
        enable     => true,
        hasrestart => true,
        hasstatus  => true,
        require     => Package['nfs-utils'],
      }
      augeas{'sl6idmapd':
         context => "/files/etc/idmapd.conf/General/",
         changes => "set Domain ihep.ac.cn",
         notify  => Service['rpcidmapd']
      }
      service{"rpcidmapd":
        ensure     =>  'running',
        enable     =>  true,
        hasstatus  =>  true,
        hasrestart =>  true,
        require     => Package['nfs-utils'],
      }
  }
}
